<?php
class ChangePassword extends Customer{
	public $old_password;
	public $confirm_password;
	public static function model($className=__CLASS__) {
		return parent::model($className);
	}


	public function rules() {
		return array(
				array('password,old_password,confirm_password', 'required'),
				array('password,old_password,confirm_password', 'length','min'=>6),
				array('old_password','exist','attributeName' => 'password','criteria'=>array('condition' => 'id = '.$this->id),'message'=>'Old Message is uncorrect!'),
				array('confirm_password','compare','compareAttribute'=>'password'),
		);
	}

	 public function beforeValidate(){
		$this->old_password = md5($this->old_password);
		return true;
	} 
	
	public function beforeSave(){
		$this->password=md5($this->password);
		return true;
	}
	
	public function attributeLabels() {
		return array(
				'id' => Yii::t('app', 'ID'),
				'user_name' => Yii::t('app', 'User Name'),
				'password' => Yii::t('app', 'New Password'),
				'old_password'=>Yii::t('app', 'Old Password'),
				'confirm_password'=>Yii::t('app', 'Confirm Password'),
				'email' => Yii::t('app', 'Email'),
				'created' => Yii::t('app', 'Created'),
				'status' => Yii::t('app', 'Status'),
		);
	}
}